package com.ming.gateway.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @Auther: tangC
 * @Date: 2020/7/7 14:22
 * @Description:
 */
@Slf4j
public class RequesuFilter implements GatewayFilter,Ordered {

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        return chain.filter(exchange).then(Mono.fromRunnable(()->{
            ServerHttpRequest request = exchange.getRequest();
            log.info(request.getPath().toString());
            log.info(request.getRemoteAddress().getAddress().toString());
            log.info(request.getQueryParams().toString());
        }));
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
